home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / helper / src / keyword.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  22.9 KB  |  959 lines

  1. /*
  2.     KEYWORD.C
  3.  
  4.     1991.01.11  make by Ken
  5. */
  6. #include    <stdio.h>
  7. #include    <stdlib.h>
  8. #include    <string.h>
  9. #include    <ctype.h>
  10. #include    <mos.h>
  11. #include    "scrn.h"
  12. #include    "keyword.h"
  13. #include    "graphic.h"
  14. #include    "dir.h"
  15. #include    "file.h"
  16. #include    "event.h"
  17. #include    "coldef.h"
  18.  
  19. #define    TRUE    1
  20. #define    FALSE    0
  21. #define    ERR    (-1)
  22.  
  23. #define KEY_HAS     8
  24.  
  25.     int    prg_max=0;
  26.     int    key_max=0;
  27.     int    prg_cnt=0;
  28.     int    prg_hit=0;
  29.     int    prg_ofs=0;
  30.     char    *crent_drive=NULL;
  31.  
  32.     PRGPTR    *prg_top=NULL;
  33.     PRGPTR    *prg_tbl[PRG_MAX];
  34.  
  35.     KEYPTR    *key_tbl[KEY_MAX];
  36. static    KEYPTR    *key_now=NULL;
  37. static    KEYPTR    *key_hash[KEY_HAS]={
  38.             NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  39.  
  40.     int    act_fwc_cdrom = 0;
  41. static    int    fwc_cdrom = 0;
  42.  
  43. char    *strdup(char *str)
  44. {
  45.     char    *p;
  46.  
  47.     if ( (p = (char *)malloc(strlen(str)+1)) != NULL )
  48.     strcpy(p,str);
  49.     return p;
  50. }
  51. static int  hash_calc(char *str)
  52. {
  53.     int     hs=0;
  54.  
  55.     while ( *str != '\0' )
  56.         hs = hs * 31 + *(str++);
  57.     return (hs & (KEY_HAS-1));
  58. }
  59. static KEYPTR *key_srch(char *key)
  60. {
  61.     int     hs;
  62.     KEYPTR  *kp;
  63.  
  64.     hs = hash_calc(key);
  65.     kp = key_hash[hs];
  66.     while ( kp != NULL ) {
  67.         if ( strcmp(key,kp->key) == 0 )
  68.         return kp;
  69.         kp = kp->next;
  70.     }
  71.  
  72.     if ( (kp = (KEYPTR *)malloc(sizeof(KEYPTR))) == NULL )
  73.         return NULL;
  74.  
  75.     kp->next = key_hash[hs];
  76.     key_hash[hs] = kp;
  77.  
  78.     kp->key = strdup(key);
  79.     kp->flg = kp->cnt = 0;
  80.     kp->over = kp->grop = NULL;
  81.  
  82.     return kp;
  83. }
  84. static void key_set(char *key,PRGPTR *pp)
  85. {
  86.     int     i,hs;
  87.     KEYPTR  *kp;
  88.  
  89.     hs = hash_calc(key);
  90.     kp = key_hash[hs];
  91.     while ( kp != NULL ) {
  92.         if ( strcmp(key,kp->key) == 0 ) {
  93.         key_now = kp;
  94.         if ( kp->grop != NULL )
  95.         kp = kp->grop;
  96.             while ( kp->cnt >= PRG_QUE ) {
  97.         for ( i = 0 ; i < kp->cnt ; i++ ) {
  98.             if ( kp->prog[i] == pp )
  99.             return;
  100.         }
  101.                 if ( kp->over == NULL ) {
  102.                     if ( (kp->over =
  103.                          (KEYPTR *)malloc(sizeof(KEYPTR))) == NULL )
  104.                         return;
  105.                     kp = kp->over;
  106.             kp->cnt = 0;
  107.             kp->over = NULL;
  108.                 } else
  109.                     kp = kp->over;
  110.             }
  111.             goto ENDOF;
  112.         }
  113.         kp = kp->next;
  114.     }
  115.  
  116.     if ( (kp = (KEYPTR *)malloc(sizeof(KEYPTR))) == NULL )
  117.         return;
  118.  
  119.     kp->next = key_hash[hs];
  120.     key_hash[hs] = kp;
  121.  
  122.     kp->key = strdup(key);
  123.     kp->flg = kp->cnt = 0;
  124.     kp->over = kp->grop = NULL;
  125.     key_now = kp;
  126.  
  127.     if ( key_max < KEY_MAX ) {
  128.     KEY_putstr(key_max,kp->key);
  129.     key_tbl[key_max++] = kp;
  130.     }
  131.  
  132. ENDOF:
  133.     if ( pp != NULL ) {
  134.     for ( i = 0 ; i < kp->cnt ; i++ ) {
  135.         if ( kp->prog[i] == pp )
  136.         return;
  137.     }
  138.     kp->prog[kp->cnt++] = pp;
  139.     }
  140. }
  141. static    int    prog_cmp(PRGPTR *sp, PRGPTR *dp)
  142. {
  143.     int c;
  144.  
  145.     if ( sp->make != NULL && dp->make != NULL &&
  146.      (c = strcmp(sp->make, dp->make)) != 0 )
  147.     return c;
  148.  
  149.     if ( sp->name == NULL )
  150.     return (-1);
  151.     else if ( dp->name == NULL )
  152.     return 1;
  153.  
  154.     return strcmp(sp->name, dp->name);
  155. }
  156. static    PRGPTR    *prog_sort(PRGPTR *np)
  157. {
  158.     PRGPTR *tp, *bp;
  159.     PRGPTR *lp, *rp;
  160.  
  161.     if ( np == NULL || np->next == NULL )
  162.         return np;
  163.  
  164.     lp = rp = NULL;
  165.     tp = np->next;
  166.  
  167.     while ( tp != NULL ) {
  168.         bp = tp->next;
  169.         if ( prog_cmp(np, tp) > 0 ) {
  170.             tp->next = lp;
  171.             lp = tp;
  172.         } else {
  173.             tp->next = rp;
  174.             rp = tp;
  175.         }
  176.         tp = bp;
  177.     }
  178.  
  179.     lp = prog_sort(lp);
  180.     rp = prog_sort(rp);
  181.  
  182.     if ( lp != NULL ) {
  183.         tp = lp;
  184.         while ( lp->next != NULL )
  185.             lp = lp->next;
  186.         lp->next = np;
  187.     } else
  188.         tp = np;
  189.  
  190.     np->next = rp;
  191.  
  192.     return tp;
  193. }
  194. static    char    *chk_drv(char *dir)
  195. {
  196.     static char tmp[BUFSIZ];
  197.  
  198.     if ( dir[0] != '\0' && dir[1] == ':' )
  199.     return dir;
  200.  
  201.     if ( crent_drive == NULL )
  202.     return dir;
  203.  
  204.     strcpy(tmp,crent_drive);
  205.     strcat(tmp,dir);
  206.     return tmp;
  207. }
  208. int    DB_init(char *file)
  209. {
  210.     int     i,n;
  211.     FILE    *fp;
  212.     PRGPTR  *pp=NULL;
  213.     KEYPTR  *kp,*tp;
  214.     char    *p,*s;
  215.     char    tmp[BUFSIZ];
  216.     char    key[BUFSIZ];
  217.  
  218.     int     pos, len;
  219.     char    buf[4096];
  220.  
  221.     prg_max = key_max = 0;
  222.  
  223.     if ( (fp = fopen(file,"rb")) == NULL )
  224.     return ERR;
  225.  
  226.     pos = len = 0;
  227.     for ( ; ; ) {
  228.     for ( i = 0 ; ; ) {
  229.         if ( pos >= len ) {
  230.             if ( (len = fread(buf, 1, 4096, fp)) <= 0 )
  231.                 goto ENDOF;
  232.             pos = 0;
  233.         }
  234.         n = buf[pos++];
  235.         if ( n == '\n' ) {
  236.         tmp[i] = '\0';
  237.         break;
  238.         } else if ( n != '\r' && n != '\x1A' )
  239.             tmp[i++] = n;
  240.     }
  241.  
  242. /**************************
  243.     while ( fgets(tmp,BUFSIZ,fp) != NULL ) {
  244.  
  245.     if ( (p = strchr(tmp,'\n')) != NULL )
  246.         *p = '\0';
  247. ****************************/
  248.  
  249.     if ( tmp[0] == '\0' || tmp[0] == '#' )
  250.         continue;
  251.  
  252.     if ( strncmp(tmp,"FEP:",4) == 0 ) {
  253.         p = &(tmp[4]);
  254.         while ( isspace(*p) )
  255.         p++;
  256.         for ( s = p ; *s != '\0' && !isspace(*s) ; s++ )
  257.         ;
  258.         if ( *s != '\0' )
  259.         *(s++) = '\0';
  260.         while ( isspace(*s) )
  261.         s++;
  262.         if ( *p != '\0' && *s != '\0' )
  263.         PROG_append(p, s);
  264.         continue;
  265.  
  266.     } else if ( strncmp(tmp,"FWC:",4) == 0 ) {
  267.         p = &(tmp[4]); while ( isspace(*p) ) p++;
  268.         fwc_cdrom = atoi(p);
  269.         if ( act_fwc_cdrom == 0 )
  270.         act_fwc_cdrom = fwc_cdrom;
  271.         continue;
  272.  
  273.     } else if ( strncmp(tmp,"DRIVE:",6) == 0 ) {
  274.         p = &(tmp[6]); while ( isspace(*p) ) p++;
  275.         if ( *p == '\0' )
  276.         continue;
  277.         crent_drive = strdup(p);
  278.         continue;
  279.  
  280.     } else if ( strncmp(tmp,"PROGRAM:",8) == 0 ) {
  281.         p = &(tmp[8]); while ( isspace(*p) ) p++;
  282.         if ( *p == '\0' )
  283.         continue;
  284.  
  285.         if ( (pp = (PRGPTR *)malloc(sizeof(PRGPTR))) == NULL )
  286.         break;
  287.  
  288.         pp->next = prg_top;
  289.         prg_top = pp;
  290.  
  291.         prg_max++;
  292.         pp->flg = pp->copycnt = pp->bits = 0;
  293.         pp->name = strdup(p);
  294.         pp->make = pp->readme = pp->manual = pp->dir = pp->exec = NULL;
  295.         pp->cdrom = fwc_cdrom;
  296.         continue;
  297.  
  298.     } else if ( strncmp(tmp,"KEYWORD:",8) == 0 ) {
  299.         p = &(tmp[8]);
  300.         while ( *p != '\0' ) {
  301.         while ( isspace(*p) ) p++;
  302.         for ( s = key ; !isspace(*p) && *p != '\0' ; )
  303.              *(s++) = *(p++);
  304.         *s = '\0';
  305.         if ( key[0] != '\0' )
  306.             key_set(key,pp);
  307.         }        
  308.         continue;
  309.  
  310.     } else    if ( strncmp(tmp,"GROUP:",6) == 0 ) {
  311.         tp = NULL;
  312.         p = &(tmp[6]);
  313.         while ( *p != '\0' ) {
  314.         while ( isspace(*p) ) p++;
  315.         for ( s = key ; !isspace(*p) && *p != '\0' ; )
  316.              *(s++) = *(p++);
  317.         *s = '\0';
  318.         if ( key[0] != '\0' ) {
  319.             if ( tp == NULL ) {
  320.                 key_set(key,NULL);
  321.             tp = key_now;
  322.             } else {
  323.             if ( (kp = key_srch(key)) != NULL )
  324.                 kp->grop = tp;
  325.             }
  326.         }
  327.         }        
  328.         continue;
  329.     }
  330.  
  331.     if ( pp == NULL )
  332.         continue;
  333.  
  334.     if ( strncmp(tmp,"MAKE:",5) == 0 ) {
  335.         p = &(tmp[6]); while ( isspace(*p) ) p++;
  336.         if ( *p != '\0' )
  337.         pp->make = strdup(p);
  338.  
  339.     } else if ( strncmp(tmp,"README:",7) == 0 ) {
  340.         p = &(tmp[7]); while ( isspace(*p) ) p++;
  341.         if ( *p != '\0' )
  342.         pp->readme = strdup(chk_drv(p));
  343.  
  344.     } else if ( strncmp(tmp,"MANUAL:",7) == 0 ) {
  345.         p = &(tmp[7]); while ( isspace(*p) ) p++;
  346.         if ( *p != '\0' )
  347.         pp->manual = strdup(chk_drv(p));
  348.  
  349.     } else if ( strncmp(tmp,"COPY:",5) == 0 ) {
  350.         p = &(tmp[5]);
  351.         while ( *p != '\0' ) {
  352.         while ( isspace(*p) ) p++;
  353.         for ( s = key ; !isspace(*p) && *p != '\0' ; )
  354.              *(s++) = *(p++);
  355.         *s = '\0';
  356.         if ( key[0] != '\0' && pp->copycnt < 16 )
  357.             pp->copy[pp->copycnt++] = strdup(chk_drv(key));
  358.         }        
  359.  
  360.     } else if ( strncmp(tmp,"DIR:",4) == 0 ) {
  361.         p = &(tmp[4]); while ( isspace(*p) ) p++;
  362.         if ( *p != '\0' )
  363.         pp->dir = strdup(chk_drv(p));
  364.  
  365.     } else if ( strncmp(tmp,"EXEC:",5) == 0 ) {
  366.         p = &(tmp[4]); while ( isspace(*p) ) p++;
  367.         if ( *p != '\0' )
  368.         pp->exec = strdup(p);
  369.     }
  370.  
  371.     }
  372.  
  373. ENDOF:
  374.     fclose(fp);
  375.  
  376. /***************************************************
  377.     for ( i = 0 ; i < 4 && i < key_max ; i++ ) {
  378.     kp = key_tbl[i];
  379.     do {
  380.         for ( n = 0 ; n < kp->cnt ; n++ )
  381.             kp->prog[n]->bits |= (1 << i);
  382.         kp = kp->over;
  383.         } while ( kp != NULL );
  384.     }
  385. *****************************************************/
  386.  
  387.     prg_top = prog_sort(prg_top);
  388.  
  389.     return FALSE;
  390. }
  391. void    PRG_alldisp(int ofs)
  392. {
  393.     int     i;
  394.     PRGPTR  *pp;
  395.  
  396.     prg_ofs = ofs;
  397.     i = 0;
  398.     for ( pp = prg_top ; prg_cnt > 0 && pp != NULL ; pp = pp->next ) {
  399.     if ( pp->flg >= prg_cnt ) {
  400.         if ( i >= ofs && (i - ofs) < PRG_MAX ) {
  401.         PRG_disp((i-ofs),pp->name,pp->make,pp->bits);
  402.         prg_tbl[i-ofs] = pp;
  403.         }
  404.         i++;
  405.     }
  406.     }
  407.     prg_hit = i;
  408.  
  409.     MENU_mask(BACK_NO,ofs > 0 ? ON:OFF);
  410.     MENU_mask(NEXT_NO,(i-ofs) > PRG_MAX ? ON:OFF);
  411.     MENU_mask(CLER_NO,prg_cnt > 0 ? ON:OFF);
  412.  
  413.     while ( i >= ofs && (i - ofs) < PRG_MAX ) {
  414.     PRG_disp((i - ofs),"","",0);
  415.     prg_tbl[i-ofs] = NULL;
  416.     i++;
  417.     }
  418.  
  419.     if ( prg_cnt == 0 )
  420.     MSG2_disp("%24s","");
  421.     else if ( prg_hit == 0 )
  422.     MSG2_disp("Not Found               ");
  423.     else
  424.     MSG2_disp("%3d Found               ",prg_hit);
  425. }
  426. void    KEY_clic(int no)
  427. {
  428.     int     i,cd;
  429.     KEYPTR  *kp;
  430.  
  431.     if ( no >= key_max )
  432.     return;
  433.  
  434.     kp = key_tbl[no];
  435.     if ( (kp->flg = (kp->flg == 0 ? 1:0)) == 0 ) {
  436.     cd = (-1);
  437.     } else {
  438.     cd = 1;
  439.     }
  440.  
  441.     KEY_disp(no);
  442.     prg_cnt += cd;
  443.     do {
  444.     for ( i = 0 ; i < kp->cnt ; i++ )
  445.         kp->prog[i]->flg += cd;
  446.     kp = kp->over;
  447.     } while ( kp != NULL );
  448.  
  449.     PRG_alldisp(0);
  450. }
  451.  
  452. static    int    titl_flg = 0;
  453. static    int    writ_flg = 0;
  454.  
  455. void    TITL_clic()
  456. {
  457.     int fg = 0;
  458.     PRGPTR  *pp;
  459.     static char tmp[130];
  460.  
  461.     if ( titl_flg ) {
  462.     prg_cnt -= 1;
  463.     for ( pp = prg_top ; pp != NULL ; pp = pp->next ) {
  464.         if ( wild_mach(tmp, pp->name) )
  465.             pp->flg -= 1;
  466.     }
  467.     titl_flg = 0;
  468.     fg = 1;
  469.     }
  470.  
  471.     if ( EXEC_input(tmp) || tmp[0] == '\0' )
  472.     goto ENDOF;
  473.  
  474.     prg_cnt += 1;
  475.     for ( pp = prg_top ; pp != NULL ; pp = pp->next ) {
  476.     if ( wild_mach(tmp, pp->name) )
  477.         pp->flg += 1;
  478.     }
  479.     titl_flg = 1;
  480.     fg = 1;
  481.  
  482. ENDOF:
  483.     if ( fg )
  484.     PRG_alldisp(0);
  485. }
  486. void    WRIT_clic()
  487. {
  488.     int fg = 0;
  489.     PRGPTR  *pp;
  490.     static char tmp[130];
  491.  
  492.     if ( writ_flg ) {
  493.     prg_cnt -= 1;
  494.     for ( pp = prg_top ; pp != NULL ; pp = pp->next ) {
  495.         if ( wild_mach(tmp, pp->make) )
  496.             pp->flg -= 1;
  497.     }
  498.     writ_flg = 0;
  499.     fg = 1;
  500.     }
  501.  
  502.     if ( EXEC_input(tmp) || tmp[0] == '\0' )
  503.     goto ENDOF;
  504.  
  505.     prg_cnt += 1;
  506.     for ( pp = prg_top ; pp != NULL ; pp = pp->next ) {
  507.     if ( wild_mach(tmp, pp->make) )
  508.         pp->flg += 1;
  509.     }
  510.     writ_flg = 1;
  511.     fg = 1;
  512.  
  513. ENDOF:
  514.     if ( fg )
  515.     PRG_alldisp(0);
  516. }
  517. void    KEY_cler(void)
  518. {
  519.     int     i;
  520.     PRGPTR  *pp;
  521.  
  522.     for ( i = 0 ; i < key_max ; i++ ) {
  523.     if ( key_tbl[i]->flg != 0 ) {
  524.         key_tbl[i]->flg = 0;
  525.         KEY_disp(i);
  526.     }
  527.     }
  528.  
  529.     for ( pp = prg_top ; pp != NULL ; pp = pp->next )
  530.     pp->flg = 0;
  531.  
  532.     for ( i = 0 ; i < PRG_MAX ; i++ ) {
  533.     PRG_disp(i,"","",0);
  534.     prg_tbl[i] = NULL;
  535.     }
  536.  
  537.     titl_flg = writ_flg = 0;
  538.     prg_cnt = prg_hit = 0;
  539.  
  540.     MENU_mask(BACK_NO,OFF);
  541.     MENU_mask(NEXT_NO,OFF);
  542.     MENU_mask(CLER_NO,OFF);
  543.  
  544.     MSG2_disp("%24s","");
  545. }
  546. void    PRG_status(void)
  547. {
  548.     MENU_mask(BACK_NO,prg_ofs > 0 ? ON:OFF);
  549.     MENU_mask(NEXT_NO,(prg_hit - prg_ofs) > PRG_MAX ? ON:OFF);
  550.     MENU_mask(CLER_NO,prg_cnt > 0 ? ON:OFF);
  551. }
  552. void    PRG_back(void)
  553. {
  554.     if ( prg_ofs <= 0 )
  555.     return;
  556.     PRG_alldisp(prg_ofs - PRG_MAX);
  557. }
  558. void    PRG_next(void)
  559. {
  560.     if ( (prg_ofs + PRG_MAX) >= prg_hit )
  561.     return;
  562.     PRG_alldisp(prg_ofs + PRG_MAX);
  563. }
  564.  
  565. /*************************************************************
  566. 01234567890123456789012345678901234567890123456789012345678901234567890123456789                01234567890123456789012345678901234567890123456
  567.                 +---------------------------------------------+
  568.                 | PROGRAM  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 
  569.                 | MAKE     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  570.                 | KEYWORD  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  571.                 | COPY     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  572.                 | README   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  573.                 | MANUAL   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  574.         | EXEC     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  575.                 | DIR      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
  576.                 |             | 設  定 | | 終  了 |           |
  577.                 +---------------------------------------------+
  578. **************************************************************/
  579.  
  580. extern char    index_file[];
  581. extern int    cut_mode;
  582. extern char    cut_buf[2][128];
  583.  
  584. #define    FILE_IDX    index_file
  585.  
  586. #define    FSEL_X1        (5*8)
  587. #define    FSEL_Y1        (235)
  588. #define    FSEL_X2        (75*8)
  589. #define    FSEL_Y2        (FSEL_Y1+220)
  590.  
  591. #define    FSEL_PROG_X    (FSEL_X1+11*8)
  592. #define    FSEL_PROG_Y    (FSEL_Y1+4)
  593.  
  594. #define    FSEL_MAKE_X    (FSEL_X1+11*8)
  595. #define    FSEL_MAKE_Y    (FSEL_Y1+1*24+4)
  596.  
  597. #define    FSEL_KEYW_X    (FSEL_X1+11*8)
  598. #define    FSEL_KEYW_Y    (FSEL_Y1+2*24+4)
  599.  
  600. #define    FSEL_COPY_X    (FSEL_X1+11*8)
  601. #define    FSEL_COPY_Y    (FSEL_Y1+3*24+4)
  602.  
  603. #define    FSEL_READ_X    (FSEL_X1+11*8)
  604. #define    FSEL_READ_Y    (FSEL_Y1+4*24+4)
  605.  
  606. #define    FSEL_MANU_X    (FSEL_X1+11*8)
  607. #define    FSEL_MANU_Y    (FSEL_Y1+5*24+4)
  608.  
  609. #define    FSEL_EXEC_X    (FSEL_X1+11*8)
  610. #define    FSEL_EXEC_Y    (FSEL_Y1+6*24+4)
  611.  
  612. #define    FSEL_DIR_X    (FSEL_X1+11*8)
  613. #define    FSEL_DIR_Y    (FSEL_Y1+7*24+4)
  614.  
  615. #define    FSEL_EXT_X    ((FSEL_X1+FSEL_X2)/2-22*8)
  616. #define    FSEL_EXT_Y    (FSEL_Y1+8*24+4)
  617.  
  618. #define    FSEL_YES_X    ((FSEL_X1+FSEL_X2)/2-10*8)
  619. #define    FSEL_YES_Y    (FSEL_Y1+8*24+4)
  620.  
  621. #define    FSEL_RET_X    ((FSEL_X1+FSEL_X2)/2+2*8)
  622. #define    FSEL_RET_Y    (FSEL_Y1+8*24+4)
  623.  
  624. #define LIST_X          (17*8)
  625. #define LIST_Y          26
  626. #define LIST_M          "マニュアル表示"
  627. #define    LIST_X1            (LIST_X-4)
  628. #define    LIST_Y1            (LIST_Y-2)
  629. #define    LIST_X2            (LIST_X+14*8+3)
  630. #define    LIST_Y2            (LIST_Y+17)
  631.  
  632. #define KEY_X           8
  633. #define KEY_Y           69
  634. #define KEY_L            (18*8)
  635. #define KEY_S            (20*8)
  636. #define KEY_POS_X(n)    ((n%4)*KEY_S+KEY_X)
  637. #define KEY_POS_Y(n)    ((n/4)*23+KEY_Y)
  638.  
  639. void    eof_chk(FILE *fp)
  640. {
  641.     int     ch;
  642.  
  643.     _setmode(fp,_BINARY);
  644.     fseek(fp,(-50L),SEEK_END);
  645.     while ( (ch = getc(fp)) != EOF && ch != 0x1A );
  646.     if ( ch == 0x1A ) {
  647.     fseek(fp,(-1L),SEEK_CUR);
  648.     } else {
  649.     clearerr(fp);
  650.     fseek(fp,0L,SEEK_END);
  651.     }
  652.     _setmode(fp,_TEXT);
  653. }
  654.  
  655. void    KEY_input(void)
  656. {
  657.     int     i,n,j;
  658.     int     sw,bx,by;
  659.     FILE    *fp;
  660.     BLOCK   *sp;
  661.     EVENT   *ep=NULL;
  662.     PRGPTR  *pp;
  663.     char    *p,*s;
  664.     char    tmp[256];
  665.     char    key[BUFSIZ];
  666.     static char dmy[8][BUFSIZ];
  667.  
  668.     if ( (fp = fopen(FILE_IDX,"r+")) == NULL ) {
  669.     if ( (fp = fopen(FILE_IDX,"w")) == NULL )
  670.         return;
  671.     } else
  672.     eof_chk(fp);
  673.  
  674.     dmy[0][0] = dmy[1][0] = dmy[2][0] = dmy[3][0] = 
  675.     dmy[4][0] = dmy[5][0] = dmy[6][0] = dmy[7][0] = '\0';
  676.  
  677.     MOS_disp(OFF);
  678.     sp = DSP_push_vram(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2);
  679.     DSP_opbox(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2);
  680.     DSP_wbox(FSEL_X1,FSEL_Y1,FSEL_X2,FSEL_Y2,LINE_COL,MENU_COL,M_PSET);
  681.  
  682.     ep = EVT_set(ep,500,LIST_X1,LIST_Y1,LIST_X2,LIST_Y2,EVT_proc);
  683.  
  684.     for ( i = 0 ; i < 28 ; i++ ) {
  685.     ep = EVT_set(ep,i+300,
  686.          KEY_POS_X(i)-4,KEY_POS_Y(i)-2,
  687.          KEY_POS_X(i)+KEY_L+3,KEY_POS_Y(i)+17,EVT_proc);
  688.     }
  689.  
  690.     sprintf(tmp,"%-44.44s",dmy[0]);
  691.     ep = EVT_sw(ep,0,FSEL_PROG_X,FSEL_PROG_Y,CHR_COL,WIND_COL,tmp);
  692.     sprintf(tmp,"%-31.31s",dmy[1]);
  693.     ep = EVT_sw(ep,1,FSEL_MAKE_X,FSEL_MAKE_Y,CHR_COL,WIND_COL,tmp);
  694.     sprintf(tmp,"%-58.58s",dmy[2]);
  695.     ep = EVT_sw(ep,2,FSEL_KEYW_X,FSEL_KEYW_Y,CHR_COL,WIND_COL,tmp);
  696.     sprintf(tmp,"%-58.58s",dmy[3]);
  697.     ep = EVT_sw(ep,3,FSEL_COPY_X,FSEL_COPY_Y,CHR_COL,WIND_COL,tmp);
  698.     sprintf(tmp,"%-58.58s",dmy[4]);
  699.     ep = EVT_sw(ep,4,FSEL_READ_X,FSEL_READ_Y,CHR_COL,WIND_COL,tmp);
  700.     sprintf(tmp,"%-58.58s",dmy[5]);
  701.     ep = EVT_sw(ep,5,FSEL_MANU_X,FSEL_MANU_Y,CHR_COL,WIND_COL,tmp);
  702.     sprintf(tmp,"%-58.58s",dmy[6]);
  703.     ep = EVT_sw(ep,6,FSEL_EXEC_X,FSEL_EXEC_Y,CHR_COL,WIND_COL,tmp);
  704.     sprintf(tmp,"%-58.58s",dmy[7]);
  705.     ep = EVT_sw(ep,7,FSEL_DIR_X,FSEL_DIR_Y,CHR_COL,WIND_COL,tmp);
  706.  
  707.     ep = EVT_sw(ep,10,FSEL_X1+8,FSEL_PROG_Y,CHR_COL,KEY_COL,"PROGRAM");
  708.     ep = EVT_sw(ep,11,FSEL_X1+8,FSEL_MAKE_Y,CHR_COL,KEY_COL,"MAKE   ");
  709.     ep = EVT_sw(ep,12,FSEL_X1+8,FSEL_KEYW_Y,CHR_COL,KEY_COL,"KEYWORD");
  710.     ep = EVT_sw(ep,13,FSEL_X1+8,FSEL_COPY_Y,CHR_COL,KEY_COL,"COPY   ");
  711.     ep = EVT_sw(ep,14,FSEL_X1+8,FSEL_READ_Y,CHR_COL,KEY_COL,"README ");
  712.     ep = EVT_sw(ep,15,FSEL_X1+8,FSEL_MANU_Y,CHR_COL,KEY_COL,"MANUAL ");
  713.     ep = EVT_sw(ep,16,FSEL_X1+8,FSEL_EXEC_Y,CHR_COL,KEY_COL,"EXEC   ");
  714.     ep = EVT_sw(ep,17,FSEL_X1+8,FSEL_DIR_Y, CHR_COL,KEY_COL,"DIR    ");
  715.  
  716.     ep = EVT_sw(ep,110,FSEL_EXT_X,FSEL_EXT_Y,CHR_COL,WIND_COL," 簡  単 ");
  717.     ep = EVT_sw(ep,100,FSEL_YES_X,FSEL_YES_Y,CHR_COL,WIND_COL," 設  定 ");
  718.     ep = EVT_sw(ep,200,FSEL_RET_X,FSEL_RET_Y,CHR_COL,WIND_COL," もどる ");
  719.  
  720.     MOS_rdpos(&sw,&bx,&by);
  721.     MOS_setpos((FSEL_X1+FSEL_X2)/2,(FSEL_Y1+FSEL_Y2)/2);
  722.     MOS_disp(ON);
  723.  
  724.     for ( ; ; ) {
  725.     i = EVT_wait(ep);
  726.  
  727.     if ( i == 0 ) {
  728.         MOS_disp(OFF);
  729.         input(FSEL_PROG_X,FSEL_PROG_Y+i*24,44,dmy[i]);
  730.         MOS_disp(ON);
  731.  
  732.     } else if ( i == 1 ) {
  733.         MOS_disp(OFF);
  734.         input(FSEL_PROG_X,FSEL_PROG_Y+i*24,31,dmy[i]);
  735.         MOS_disp(ON);
  736.  
  737.     } else if ( i >= 2 && i <= 7 ) {
  738.         MOS_disp(OFF);
  739.         input(FSEL_PROG_X,FSEL_PROG_Y+i*24,58,dmy[i]);
  740.         MOS_disp(ON);
  741.  
  742.     } else if ( i >= 10 && i <= 11 ) {
  743.         if ( (p = FILE_select()) != NULL ) {
  744.         MENU_mask(RETN_NO,ON);
  745.         cut_mode = TRUE;
  746.         cut_buf[0][0] = '\0';
  747.         FILE_open(p);
  748.         while ( MENU_no(0) != CLER_NO )
  749.             FILE_irq();
  750.         MENU_mask(CLER_NO,OFF);
  751.         FILE_close();
  752.         cut_mode = FALSE;
  753.  
  754.         n = i - 10;
  755.         strcat(dmy[n],cut_buf[0]);
  756.  
  757.         MOS_disp(OFF);
  758.         gprintf(FSEL_PROG_X,FSEL_PROG_Y+n*24,
  759.             CHR_COL,WIND_COL,
  760.              n == 0 ? "%-44.44s":
  761.             (n == 1 ? "%-31.31s":
  762.                   "%-58.58s"),dmy[n]);
  763.         MOS_disp(ON);
  764.         }
  765.  
  766.     } else if ( i == 110 ) {
  767.         if ( (p = FILE_select()) != NULL ) {
  768.         MENU_mask(RETN_NO,ON);
  769.         cut_mode = TRUE;
  770.         cut_buf[0][0] = cut_buf[1][0] = '\0';
  771.         FILE_open(p);
  772.         while ( (n = MENU_no(0)) != CLER_NO ) {
  773.             FILE_irq();
  774.             if ( n == BACK_NO )
  775.             FILE_back();
  776.             else if ( n == NEXT_NO )
  777.             FILE_next();
  778.         }
  779.         MENU_mask(CLER_NO,OFF);
  780.         FILE_close();
  781.         cut_mode = FALSE;
  782.  
  783.         strcpy(dmy[0],cut_buf[0]);
  784.         strcpy(dmy[1],cut_buf[1]);
  785.         getdir(dmy[7]);
  786.  
  787.         MOS_disp(OFF);
  788.         gprintf(FSEL_PROG_X,FSEL_PROG_Y,
  789.             CHR_COL,WIND_COL,"%-44.44s",dmy[0]);
  790.         gprintf(FSEL_MAKE_X,FSEL_MAKE_Y,
  791.             CHR_COL,WIND_COL,"%-31.31s",dmy[1]);
  792.             CHR_COL,WIND_COL,
  793.         gprintf(FSEL_DIR_X,FSEL_DIR_Y,
  794.             CHR_COL,WIND_COL,"%-58.58s",dmy[7]);
  795.             MOS_disp(ON);
  796.         }
  797.  
  798.     } else if ( i >= 13 && i <= 16 ) {
  799.         if ( (p = FILE_select()) != NULL ) {
  800. /********************************************
  801.         tmp[0] = 'A' + getdrv();
  802.         tmp[1] = ':';
  803.         getdir(tmp+2);
  804.         if ( tmp[3] != '\0' )
  805.             strcat(tmp,"\\");
  806.         strcat(tmp,p);
  807. *********************************************/
  808.         getdir(tmp);
  809.         if ( tmp[1] != '\0' )
  810.             strcat(tmp,"\\");
  811.         strcat(tmp,p);
  812.  
  813.         n = i - 10;
  814.         if ( dmy[n][0] != '\0' )
  815.             strcat(dmy[n]," ");
  816.         strcat(dmy[n],tmp);
  817.  
  818.         MOS_disp(OFF);
  819.         gprintf(FSEL_PROG_X,FSEL_PROG_Y+n*24,
  820.                 CHR_COL,WIND_COL,"%-58.58s",dmy[n]);
  821.             MOS_disp(ON);
  822.         }
  823.  
  824.     } else if ( i == 16 ) {
  825.         FILE_select();
  826. /*******************************************
  827.         tmp[0] = 'A' + getdrv();
  828.         tmp[1] = ':';
  829.         getdir(tmp+2);
  830. *******************************************/
  831.         getdir(tmp);
  832.  
  833.         n = i - 10;
  834.         strcpy(dmy[n],tmp);
  835.  
  836.         MOS_disp(OFF);
  837.         gprintf(FSEL_PROG_X,FSEL_PROG_Y+n*24,
  838.             CHR_COL,WIND_COL,"%-58.58s",dmy[n]);
  839.         MOS_disp(ON);
  840.  
  841.     } else if ( i == 500 ) {
  842.         LIST_proc();
  843.  
  844.     } else if ( i >= 300 ) {
  845.         if ( key_tbl[i-300] != NULL ) {
  846.         if ( dmy[2][0] != '\0' )
  847.             strcat(dmy[2]," ");
  848.         strcat(dmy[2],key_tbl[i-300]->key);
  849.         MOS_disp(OFF);
  850.         gprintf(FSEL_KEYW_X,FSEL_KEYW_Y,
  851.                 CHR_COL,WIND_COL,"%-58.58s",dmy[2]);
  852.         MOS_disp(ON);
  853.         }
  854.  
  855.     } else if ( i == 100 ) {
  856.         if ( dmy[0][0] == '\0' &&
  857.         yesno("作品名が無いけど?") == ERR )
  858.         continue;
  859.         if ( dmy[1][0] == '\0' &&
  860.         yesno("作者名が無いけど?") == ERR )
  861.         continue;
  862.         if ( dmy[2][0] == '\0' &&
  863.         yesno("キ-ワ-ドが無いけど?") == ERR )
  864.         continue;
  865.         if ( dmy[3][0] == '\0' && dmy[4][0] == '\0' &&
  866.              dmy[5][0] == '\0' && dmy[7][0] == '\0' &&
  867.         yesno("ファイル指定が無いけど?") == ERR )
  868.         continue;
  869.  
  870.         fprintf(fp,"\n");
  871.         fprintf(fp,"PROGRAM: %s\n",dmy[0]);
  872.         fprintf(fp,"MAKE:    %s\n",dmy[1]);
  873.         fprintf(fp,"KEYWORD: %s\n",dmy[2]);
  874.         if ( dmy[3][0] != '\0' )
  875.         fprintf(fp,"COPY:    %s\n",dmy[3]);
  876.         if ( dmy[4][0] != '\0' )
  877.         fprintf(fp,"README:  %s\n",dmy[4]);
  878.         if ( dmy[5][0] != '\0' )
  879.         fprintf(fp,"MANUAL:  %s\n",dmy[5]);
  880.         if ( dmy[6][0] != '\0' )
  881.         fprintf(fp,"EXEC:    %s\n",dmy[6]);
  882.         if ( dmy[7][0] != '\0' )
  883.         fprintf(fp,"DIR:     %s\n",dmy[7]);
  884.  
  885.         if ( (pp = (PRGPTR *)malloc(sizeof(PRGPTR))) == NULL )
  886.         break;
  887.         pp->next = prg_top;
  888.         prg_top = pp;
  889.         prg_max++;
  890.         pp->flg = pp->copycnt = pp->bits = 0;
  891.         pp->name = strdup(dmy[0]);
  892.         pp->make = pp->readme = pp->manual = pp->exec = pp->dir = NULL;
  893.  
  894.         if ( dmy[1][0] != '\0' )
  895.         pp->make = strdup(dmy[1]);
  896.         if ( dmy[4][0] != '\0' )
  897.         pp->readme = strdup(chk_drv(dmy[4]));
  898.         if ( dmy[5][0] != '\0' )
  899.         pp->manual = strdup(chk_drv(dmy[5]));
  900.         if ( dmy[6][0] != '\0' )
  901.         pp->exec   = strdup(chk_drv(dmy[6]));
  902.         if ( dmy[7][0] != '\0' )
  903.         pp->dir    = strdup(chk_drv(dmy[7]));
  904.  
  905.         p = dmy[3];
  906.         while ( *p != '\0' ) {
  907.         while ( isspace(*p) ) p++;
  908.         for ( s = key ; !isspace(*p) && *p != '\0' ; )
  909.              *(s++) = *(p++);
  910.         *s = '\0';
  911.         if ( key[0] != '\0' && pp->copycnt < 16 )
  912.             pp->copy[pp->copycnt++] = strdup(chk_drv(key));
  913.         }        
  914.  
  915.         p = dmy[2];
  916.         while ( *p != '\0' ) {
  917.         while ( isspace(*p) ) p++;
  918.         for ( s = key ; !isspace(*p) && *p != '\0' ; )
  919.              *(s++) = *(p++);
  920.         *s = '\0';
  921.         if ( key[0] != '\0' )
  922.             key_set(key,pp);
  923.         }        
  924.  
  925.         dmy[0][0] = dmy[1][0] = dmy[2][0] = dmy[3][0] = 
  926.         dmy[4][0] = dmy[5][0] = dmy[6][0] = dmy[7][0] = '\0';
  927.  
  928.         MOS_disp(OFF);
  929.         gprintf(FSEL_PROG_X,FSEL_PROG_Y,
  930.             CHR_COL,WIND_COL,"%-44.44s",dmy[0]);
  931.         gprintf(FSEL_MAKE_X,FSEL_MAKE_Y,
  932.             CHR_COL,WIND_COL,"%-31.31s",dmy[1]);
  933.         gprintf(FSEL_KEYW_X,FSEL_KEYW_Y,
  934.             CHR_COL,WIND_COL,"%-58.58s",dmy[2]);
  935.         gprintf(FSEL_COPY_X,FSEL_COPY_Y,
  936.             CHR_COL,WIND_COL,"%-58.58s",dmy[3]);
  937.         gprintf(FSEL_READ_X,FSEL_READ_Y,
  938.             CHR_COL,WIND_COL,"%-58.58s",dmy[4]);
  939.         gprintf(FSEL_MANU_X,FSEL_MANU_Y,
  940.             CHR_COL,WIND_COL,"%-58.58s",dmy[5]);
  941.         gprintf(FSEL_EXEC_X,FSEL_EXEC_Y,
  942.             CHR_COL,WIND_COL,"%-58.58s",dmy[6]);
  943.         gprintf(FSEL_DIR_X,FSEL_DIR_Y,
  944.             CHR_COL,WIND_COL,"%-58.58s",dmy[7]);
  945.         MOS_disp(ON);
  946.  
  947.     } else if ( i == 200 ) {
  948.         break;
  949.     }
  950.     }
  951.  
  952.     EVT_free(ep);
  953.     MOS_disp(OFF);
  954.     DSP_pop_vram(sp);
  955.     MOS_setpos(bx,by);
  956.     MOS_disp(ON);
  957.     fclose(fp);
  958. }
  959.